package com.liu.example.auto;

import com.liu.example.properties.HelloProperties;
import com.liu.example.service.HelloService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 底层注解
 *    -@Configuration详解
 *    -@Import导入组件，给容器中自动创建出组件、默认组件的名字就是全类名
 *    -@Conditional条件装配
 *    -@ImportResource导入Spring配置文件
 *    -@ConfigurationProperties配置绑定
 *
 */

@Configuration

//容器中不存在HelloService，HelloServiceAutoConfiguration类的Bean才能生效。
@ConditionalOnMissingBean(HelloService.class)
//把HelloProperties默认放在容器中
@EnableConfigurationProperties(HelloProperties.class)
public class HelloServiceAutoConfiguration {

    @Bean
    public HelloService helloService(){
        return new HelloService();
    }
}
